package com.pf.config;

import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CustomUrlHelper {

    //    private static CustomProperties customProperties;
    private static Map<String, CustomProperties.UrlDTO> urlMap = new HashMap<String, CustomProperties.UrlDTO>();

//    @Autowired
//    public void setCustomProperties(CustomProperties customProperties) {
//        CustomUrlHelper.customProperties = customProperties;
//        List<CustomProperties.UrlDTO> urls = customProperties.getUrls();
//        urls.forEach(urlDTO -> {
//            String key = urlDTO.getHttpMethod() + "-" + urlDTO.getUrl();
//            urlMap.put(key, urlDTO);
//        });
//    }

    @Autowired
    private CustomProperties customProperties;

    @PostConstruct
    public void initUrlData() {
        List<CustomProperties.UrlDTO> urls = customProperties.getUrls();
        if (urls != null) {
            urls.forEach(urlDTO -> {
                String key = urlDTO.getHttpMethod() + "-" + urlDTO.getUrl();
                urlMap.put(key, urlDTO);
            });
        }
        System.out.println(">>>>> urlMap size=" + urlMap.size() + ">>>>> data=" + urlMap);
    }


    public CustomProperties.UrlDTO getUrlDTO(String key) {
        return urlMap.get(key);
    }
}
